package com.csdj.springcloudt309.user.controller;

import com.csdj.spingcloudt309.common.entity.User;
import com.csdj.springcloudt309.user.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("/info/{id}")
    public User getUserInfo(@PathVariable("id")Integer id){
        User user = new User();
        user.setAddress("csdj");
        user.setBirthday(LocalDate.now());
        user.setId(id);
        user.setNickName("test");
        user.setUsername("cloud");
        user.setEmail("test@test.com");
        return user;
    }

    @PutMapping("/add")
    public int saveUser(@RequestBody User user){
        return userService.save(user)?1:0;
    }
}
